package com.projet.glb2r.Activite;





import java.util.ArrayList;
import java.util.List;

import com.projet.glb2r.R;
import com.projet.glb2r.DAO.DAOClient;
import com.projet.glb2r.DAO.DAOProduit;
import com.projet.glb2r.DAO.DAOProduitsFactures;
import com.projet.glb2r.Objet.ObjetClient;
import com.projet.glb2r.Objet.ObjetClientAdapter;
import com.projet.glb2r.Objet.ObjetProduit;
import com.projet.glb2r.Objet.ObjetProduitAdapter;
import com.projet.glb2r.Objet.ObjetProduitsFactures;
import com.projet.glb2r.R.id;
import com.projet.glb2r.R.layout;
import com.projet.glb2r.R.menu;

import android.app.Activity;
import android.app.Dialog;
import android.content.Intent;
import android.os.Bundle;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ListView;
import android.widget.TextView;

public class ActiviteListClient extends Activity{

		private Dialog d;
		public ObjetClient client = new ObjetClient();
		public static ArrayList<ObjetClient> iclient = new ArrayList<ObjetClient>();
		private DAOClient clientDAO = new DAOClient();
		private ListView listeViewClient;
		private ObjetClientAdapter adapter;
		

		
		@Override
		public void onCreate(Bundle savedInstanceState) {
			super.onCreate(savedInstanceState);
			setContentView(R.layout.list_client);
			
						//ActiviteCreationFacture.listeProduits = produitsfactures;
						
			
			listeViewClient = (ListView) findViewById(R.id.listeclient);
			adapter = new ObjetClientAdapter(this, clientDAO.getAllClient(getContentResolver()));
			
			listeViewClient.setAdapter(adapter);
			registerForContextMenu(listeViewClient);
			for(int i=0; i<iclient.size(); i++){
				client = iclient.get(i);
			}
		}

		
				
		private void updateAdapter() {
			adapter.setClient(clientDAO.getAllClient(getContentResolver()));
			adapter.notifyDataSetChanged();
		}
				
		
		
		public void DeleteItem(int id) {
			//produitRepository.Delete(id);
		
		}
		
		@Override
		public void onCreateContextMenu(ContextMenu menu, View v,
				ContextMenuInfo menuInfo) {
			super.onCreateContextMenu(menu, v, menuInfo);
			getMenuInflater().inflate(R.menu.menu_suprimer, menu);
		}
		
		@Override
		public boolean onCreateOptionsMenu(Menu menu) {
			super.onCreateOptionsMenu (menu);
			MenuInflater awesome = getMenuInflater();
			awesome.inflate(R.menu.options_menu, menu);
			return true;
		}
	
		@Override
		public boolean onOptionsItemSelected(MenuItem item) {
			AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
					.getMenuInfo();

			switch (item.getItemId()) {
			case R.id.itemDelete:
				DeleteItem((int) info.id);
				updateAdapter();
				return true;

			case R.id.itemModifier:
				Intent intention = new Intent("android.intent.action.ActiviteModifierClient");
				startActivity(intention);
				
			default:
				return super.onContextItemSelected(item);
			}
		}

		@Override
		public boolean onContextItemSelected(MenuItem item) {
			AdapterContextMenuInfo info = (AdapterContextMenuInfo) item
					.getMenuInfo();
			
			switch (item.getItemId()) {
			case R.id.itemDelete:
				DeleteItem((int) info.id);
				updateAdapter();
				return true;

			case R.id.itemModifier:
				Intent intention2 = new Intent("android.intent.action.ActiviteModifierClient");
				startActivity(intention2);
				
			default:
				return super.onContextItemSelected(item);
			}
		}

		public void onClick(View v) {
		}
		

}





